var Dialog = new function(){
	/** 在Dialog中显示一个DIV */
	this.showDIV = function(title, close, divid, modal){
		if(modal) { this.showLayer(true); }
		var dlg = this.createDialog(title, close);
		dlg.children('.dialog-content').append($('#' + divid).css({display:'block'}));
		this.adjustDialog(dlg);
	};
	/** 在Dialog中显示一段HTML */
	this.showHTML = function(title, close, html, modal){
		if(modal) { this.showLayer(true); }
		var dlg = this.createDialog(title, close);
		dlg.children('.dialog-content').html(html);
		this.adjustDialog(dlg);
	};
	/** 在Dialog中显示一个URL */
	this.showURL = function(title, close, url, width, height, modal){
		if(modal) { this.showLayer(true); }
		var dlg = this.createDialog(title, close);
		dlg.children('.dialog-content').append('<iframe frameborder="0" width="'+width+'px" height="'+height+'px" src="'+url+'"></iframe>');
		this.adjustDialog(dlg);
	};
	/** 关闭Dialog */
	this.close = function(digId){
		$('#'+digId).addClass('hide').remove();
		this.showLayer(false);
		$('body').remove('#'+digId);
	}
	this.createDialog = function(title, close){
		var dlgId = 'dlg_' + new Date().getTime();
		var dlg = $('<div class="dialog txtl hide"></div>').attr('id', dlgId);
		var btnHtml = close ? '<div class="close-button"><a href="javascript:void(0);" onclick="Dialog.close(\''+dlgId+'\')">X</a></div>' : '';
		dlg.append('<div class="dialog-title"><span>' + title + '</span>' + btnHtml + '</div>').append('<div class="dialog-content"></div>').appendTo('body');
		return dlg;
	};
	this.adjustDialog = function(dlg){
		var x = ($(document).width() - dlg.width()) / 2 + 'px';
		var y = ($(document).height() - dlg.height()) / 4 + 'px';
		dlg.css({left:x,top:y}).fadeIn(500);//.removeClass('hide');
	};
	this.showLayer = function(show){
		var dlgly = $('#dlg_layer');
		if(dlgly.length == 0){ dlgly = $('<div id="dlg_layer" class="hide"></div>').appendTo('body'); }
		eval('dlgly.' + (show ? 'remove' : 'add') + 'Class("hide");');
		// 显示一个iframe层，用于覆盖flash
		//var dlglf = $('#dlg_layer_frame');
		//if(dlglf.length == 0){ dlglf = $('<iframe id="dlg_layer_frame" frameborder="0" class="hide"></div>').appendTo('body'); }
		//eval('dlglf.' + (show ? 'remove' : 'add') + 'Class("hide");');
	};
}